home *** CD-ROM | disk | FTP | other *** search
Text File | 1990-10-25 | 6.9 KB | 261 lines | [TEXT/MPS ] |
- {Copyright © 1989 by Apple Computer, Inc. All rights reserved.}
-
-
-
- CONST
- kIconHBits = 32; { Number of horizontal bits in a bitmap.}
- kIconVBits = 32; { Number of vertical bits in a bitmap. }
-
- kIconSizeInBytes = kIconHBits * kIconVBits DIV 8; { Number of bytes in an bitmap. }
- kIconSizeInLongs = kIconSizeInBytes DIV 4; { Number of long words in a bitmap. }
- kMaxLong = kIconSizeInLongs - 1; { Max. addressable long word in bitmap. }
-
-
-
- TYPE
- LongArrayHdl = ^LongArrayPtr;
- LongArrayPtr = ^LongArray;
- LongArray = ARRAY [0..kMaxLong] OF LONGINT;
-
-
-
- {-------------------------------------------------------------------------------------------}
- {--------------------------------TIconApplication methods-----------------------------------}
- {-------------------------------------------------------------------------------------------}
-
- PROCEDURE TIconApplication.IIconApplication(iconFileType: OSType);
-
- BEGIN
- IApplication(iconFileType);
- END;
-
-
-
- {-------------------------------------------------------------------------------------------}
-
- FUNCTION TIconApplication.DoMakeDocument(itsCmdNumber: CmdNumber): TDocument; OVERRIDE;
-
- VAR
- anIconDocument: TIconDocument;
-
- BEGIN
- New(anIconDocument); { Create a TIconDocument object. }
- FailNIL(anIconDocument); { Make sure we were successful. }
- anIconDocument.IIconDocument; { Initialize it. }
-
- DoMakeDocument := anIconDocument; { Return a reference to the document. }
- END;
-
-
-
-
- {-------------------------------------------------------------------------------------------}
- {----------------------------------TIconDocument methods------------------------------------}
- {-------------------------------------------------------------------------------------------}
-
- PROCEDURE TIconDocument.IIconDocument;
-
- VAR anIconBitMap : TIconBitMap;
-
- BEGIN
- fIconBitMap := NIL; { Set this to NIL so that if IDocument }
- { fails, TIconDocument.Free works okay. }
-
- IDocument(kFileType, { This document's file type. }
- kSignature, { This document's creator. }
- kUsesDataFork, { This document does use the data fork }
- NOT kUsesRsrcFork, { …but doesn't use the resource fork. }
- NOT kDataOpen, { We don't want the data fork kept open }
- NOT kRsrcOpen); { …nor the resource fork. }
-
- New(anIconBitMap); { Allocate a new icon bitmap. }
- FailNil(anIconBitMap); { Fail if we can't allocate the handle. }
- anIconBitMap.IIconBitMap; { Initialize it. }
-
- fIconBitMap := anIconBitMap; { Store the reference in a field. }
- END;
-
-
-
- {-------------------------------------------------------------------------------------------}
-
- PROCEDURE TIconDocument.DoInitialState; OVERRIDE;
-
-
- BEGIN
- fIconBitMap.Clear;
- END;
-
-
-
- {-------------------------------------------------------------------------------------------}
-
- PROCEDURE TIconDocument.Free; OVERRIDE;
-
- BEGIN
- FreeIfObject(fIconBitMap); { Dispose of the icon object if non-Nil.}
-
- INHERITED Free;
- END;
-
-
-
- {-------------------------------------------------------------------------------------------}
-
- PROCEDURE TIconDocument.DoMakeViews(forPrinting: boolean); OVERRIDE;
-
- BEGIN
- { Do nothing for now. }
- END;
-
-
-
-
- {-------------------------------------------------------------------------------------------}
- {-----------------------------------TIconBitMap methods-------------------------------------}
- {-------------------------------------------------------------------------------------------}
-
- PROCEDURE TIconBitMap.IIconBitMap;
-
- BEGIN
- fDataHandle := NewPermHandle(kIconSizeInBytes); { Allocate a handle for the bitmap. }
- FailNil(fDataHandle); { Fail if we can't allocate the handle. }
- END;
-
-
-
- {-------------------------------------------------------------------------------------------}
-
- PROCEDURE TIconBitMap.Free; OVERRIDE;
-
- BEGIN
- DisposIfHandle(fDataHandle); { dispose of icon data. }
- END;
-
-
-
- {-------------------------------------------------------------------------------------------}
-
- PROCEDURE TIconBitMap.SetIconBitMap(theBitMap : Handle);
-
- BEGIN
- BlockMove(theBitMap^, fDataHandle^, { …then copy it into the document's }
- kIconSizeInBytes) { …icon bitmap. }
- END;
-
-
-
- {-------------------------------------------------------------------------------------------}
-
- PROCEDURE TIconBitMap.Clear;
-
- VAR
- iconAsLongArray: LongArrayHdl;
- i: INTEGER;
-
- BEGIN
- iconAsLongArray := LongArrayHdl(fDataHandle); { Cast to array of longints. }
-
- FOR i := 0 TO kMaxLong DO { Clear the bits 32 at a time. }
- iconAsLongArray^^[i] := 0;
- END;
-
-
-
- {-------------------------------------------------------------------------------------------}
-
- PROCEDURE TIconBitMap.Invert;
-
- VAR
- iconAsLongArray: LongArrayHdl;
- i: INTEGER;
-
- BEGIN
- iconAsLongArray := LongArrayHdl(fDataHandle); { Cast to array of longints. }
-
- FOR i := 0 TO kMaxLong DO { Invert the bits 32 at a time. }
- iconAsLongArray^^[i] := BNOT(iconAsLongArray^^[i]);
- END;
-
-
-
- {-------------------------------------------------------------------------------------------}
-
- PROCEDURE TIconBitMap.IconBitToWordBit (iconBit: Point; VAR word, bit: INTEGER);
- { This converts the given icon bit to a word and bit in an array of long words. }
-
- VAR
- bitNumber: INTEGER;
-
- BEGIN
- bitNumber := iconBit.v * kIconVBits + iconBit.h;
- word := bitNumber DIV 32;
- bit := 31 - (bitNumber MOD 32);
- END;
-
-
-
- {-------------------------------------------------------------------------------------------}
-
- FUNCTION TIconBitMap.GetBit (iconBit: Point): BOOLEAN;
- { Returns the state of the given bit in the icon being drawn. }
-
- VAR
- word: INTEGER;
- bitInWord: INTEGER;
-
- BEGIN
- IconBitToWordBit(iconBit, word, bitInWord);
-
- GetBit := BTst(LongArrayHdl(fDataHandle)^^[word], bitInWord);
- END;
-
-
-
- {-------------------------------------------------------------------------------------------}
-
- PROCEDURE TIconBitMap.SetBit (iconBit: Point; turnBitOn: BOOLEAN);
- { Set the state of the given bit in the icon being drawn. }
-
- VAR
- word: INTEGER;
- bitInWord: INTEGER;
-
- BEGIN
- IconBitToWordBit(iconBit, word, bitInWord);
-
- {$H-} { So the compiler thinks this is unsafe.}
- IF turnBitOn THEN
- BSet(LongArrayHdl(fDataHandle)^^[word], bitInWord)
- ELSE
- BClr(LongArrayHdl(fDataHandle)^^[word], bitInWord);
- {$H+}
- END;
-
-
-
- {-------------------------------------------------------------------------------------------}
-
- FUNCTION TIconBitMap.Copy: TIconBitMap;
-
- VAR
- copyOfIcon: TIconBitMap;
-
- BEGIN
- New(copyOfIcon); { Create a TIcon object. }
- FailNIL(copyOfIcon); { Make sure we were successful. }
- copyOfIcon.IIconBitMap; { Initialize it. }
- copyOfIcon.SetIconBitMap(fDataHandle); { Copy the data. }
- Copy := copyOfIcon; { Return a reference to the new handle. }
- END;
-
-
-
- {-------------------------------------------------------------------------------------------}
-
- PROCEDURE TIconBitMap.CopyDataTo (anIcon: TIconBitMap);
-
- BEGIN
- anIcon.SetIconBitMap(fDataHandle); { Copy data to the new icon. }
- END;
-